﻿using Abp;
using Abp.AspNetCore;
using Abp.AspNetCore.Configuration;
using Abp.AutoMapper;
using Abp.Configuration.Startup;
using Abp.Dependency;
using Abp.EntityHistory;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Abp.Threading.Timers;
using Abp.Timing;
using KelonProud.Administration.Configuration;
using KelonProud.Domain.Entitys;
using KelonProud.Timing;

namespace KelonProud.Administration
{
    [DependsOn(typeof(KelonProudModule),
        typeof(AbpKernelModule),
        typeof(AbpAspNetCoreModule),
        typeof(AbpAutoMapperModule))]
    public class KelonProudDomainBaseModule : AbpModule
    {
        public override void PreInitialize()
        {
            //// Declare entity types
         

            //// Enable this line to create a multi-tenant application.
          
            //实体历史
            Configuration.EntityHistory.Selectors.Add(new NamedTypeSelector("Kelon.AuditEntity", 
                type => typeof(IAuditEntity).IsAssignableFrom(type)));


            //Configuration.Modules.AbpAspNetCore()
            //    .CreateControllersForAppServices(typeof(HonkSoftAdministrationModule).Assembly,
            //        "Administration",
            //        useConventionalHttpVerbs: false);
        }

        public override void Initialize()
        {
            var thisAssembly = typeof(KelonProudDomainBaseModule).GetAssembly();

            IocManager.RegisterAssemblyByConvention(thisAssembly);

            Configuration.Modules.AbpAutoMapper().Configurators.Add(
                // Scan the assembly for classes which inherit from AutoMapper.Profile
                cfg => cfg.AddProfiles(thisAssembly)
            );

            //Configuration.EmbeddedResources.Sources.Add(
            //    new EmbeddedResourceSet(
            //        "/Views/",
            //        thisAssembly,
            //        "HonkSoft.Administration.Views"
            //    )
            //);
        }

        public override void PostInitialize()
        {
            IocManager.Resolve<AppTimes>().StartupTime = Clock.Now;
        }
    }
}
